<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
     
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="退款金额"
          hasFeedback >
          <a-input placeholder="可修改退款金额" v-model="returnMoney" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="备注"
          hasFeedback >
          <a-input placeholder="请输入备注" v-model="remark" />
        </a-form-item>


 
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
 import JImageUpload from '../../../components/jeecg/JImageUpload'
  export default {
    name: "ConfirmRefund",
     components: {
      JImageUpload
    },
    data () {
      return {
				orderSn:'',
		  orderMoney:'',
		  orderType:'',
		  cartId:'',
		  id:'',
		  returnMoney:'',
		  remark:'',
         fileList: [],
        supplierId:'',
        pingzheng:'',
        userId:'',
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          add: "/returnMoney/approve",
          edit: "/returnMoney/approve",
        },
      }
    },
    created () {
    },
    methods: {
       //上传图片成功函数
      handleSuccess(response, file, fileList) {
        var result = response;
        this.pingzheng = result.data;
      },
      add () {
        this.edit({});
      },
      edit (record) {
		  this.orderSn=record.orderSn;
		  
			this.orderMoney=record.orderMoney;
				this.orderType=record.orderType;
				 this.cartId=record.cartId;
        this.id=record.id;
		this.returnMoney=record.returnMoney;
        this.userId=record.userId;
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'name','keyWord','sex','age','email','content'))
		      //时间格式化
          this.form.setFieldsValue({punchTime:this.model.punchTime?moment(this.model.punchTime,'YYYY-MM-DD HH:mm:ss'):null})
          this.form.setFieldsValue({birthday:this.model.birthday?moment(this.model.birthday):null})
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'get';
            }else{
              httpurl+=this.url.edit;
               method = 'get';
            }
            let formData = Object.assign(this.model, values);

            //时间格式化
    //         formData.punchTime = formData.punchTime?formData.punchTime.format('YYYY-MM-DD HH:mm:ss'):null;
    //         formData.birthday = formData.birthday?formData.birthday.format():null;
    //         formData['userId']=this.userId;
    //         formData['returnMoney']=this.returnMoney;
    //          formData['remark']=this.remark;
			 // formData['id']=this.id;
         
		 getAction(this.url.edit,{'userId':this.userId,'money':this.returnMoney,'id':this.id,'remark':this.remark,'orderType':this.orderType,'cartId':this.cartId,'orderMoney':this.orderMoney,'orderSn':this.orderSn}).then((res)=>{
		   if(res.success){
		     this.$message.success(res.message);
		     this.$emit('aaa');
		   }else{
		     this.$message.warning(res.message);
		   } }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
		 
   //          httpAction(httpurl,{'userId':this.userId,'returnMoney':this.returnMoney,'id':this.id,'remark':this.remark},method).then((res)=>{
   //            if(res.success){
   //              that.$message.success(res.message);
   //              that.$emit('aaa');
   //            }else{
   //              that.$message.warning(res.message);
   //            }
   //          }).finally(() => {
   //            that.confirmLoading = false;
   //            that.close();
   //          })

          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style scoped>

</style>